//
//  NOnlineFocusModel.m
//  News
//
//  Created by zhangtao on 2018/12/3.
//  Copyright © 2018 zt.td. All rights reserved.
//

#import "NOnlineFocusModel.h"

@implementation NOnlineFocusModel

static NOnlineFocusModel *model = nil;
+(instancetype)sharedInstance{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        model = [[NOnlineFocusModel alloc]init];
    });
    return model;
}

-(void)initPropertyWithID:(NSNumber *)ID{
    model.fouceArray = [NSMutableArray arrayWithCapacity:0];
    model.nameArray = [NSMutableArray arrayWithCapacity:0];
    model.ids = [NSString stringWithFormat:@"%@",ID];
}

-(void)addFouce:(NSDictionary *)dic{
    if (!model.fouceArray) {
        [model initPropertyWithID:dic[@"ID"]];
//        model.fouceArray = [NSMutableArray arrayWithCapacity:0];
//        model.nameArray = [NSMutableArray arrayWithCapacity:0];
//        model.ids = [NSString stringWithFormat:@"%@",dic[@"ID"]];
    }else{
        model.ids = [model.ids stringByAppendingString:[NSString stringWithFormat:@",%@",dic[@"ID"]]];
    }
    [model.fouceArray addObject:dic[@"ID"]];
    [model.nameArray addObject:dic[@"TopicalName"]];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:firstRequestFocusSuccess object:nil];
}

-(void)addfouce:(NSNumber *)ID name:(NSString *)name{
    if (!model.fouceArray) {
        [model initPropertyWithID:ID];

//        model.fouceArray = [NSMutableArray arrayWithCapacity:0];
//        model.nameArray = [NSMutableArray arrayWithCapacity:0];
//        model.ids = [NSString stringWithFormat:@"%@",ID];
    }else{
        model.ids = [model.ids stringByAppendingString:[NSString stringWithFormat:@",%@",ID]];
    }
    
    [model.fouceArray addObject:ID];
    [model.nameArray addObject:name];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:firstRequestFocusSuccess object:nil];

}

-(void)addFouceWithArray:(NSArray *)array{
    if (!model.fouceArray) {
        [model initPropertyWithID:array.firstObject[@"ID"]];
//        model.fouceArray = [NSMutableArray arrayWithCapacity:0];
//        model.nameArray = [NSMutableArray arrayWithCapacity:0];
//        model.ids = [NSString stringWithFormat:@"%@",array.firstObject[@"ID"]];
    }else{
    }
    
    for (NSDictionary *dic in array) {
        [model.fouceArray addObject:dic[@"ID"]];
        [model.nameArray addObject:dic[@"TopicalName"]];
        model.ids = [model.ids stringByAppendingString:[NSString stringWithFormat:@",%@",dic[@"ID"]]];

    }
    
    [[NSNotificationCenter defaultCenter]postNotificationName:firstRequestFocusSuccess object:nil];


}

-(void)deleteFouceId:(NSNumber *)topicId{
    NSInteger index = [model.fouceArray indexOfObject:topicId];
    [model.nameArray removeObjectAtIndex:index];
    [model.fouceArray removeObject:topicId];
    
    if (model.fouceArray.count>0) {
        NSString *str = [NSString stringWithFormat:@"%@",model.fouceArray.firstObject];
        for (int i = 1; i<model.fouceArray.count; i++) {
            str = [str stringByAppendingString:[NSString stringWithFormat:@",%@",model.fouceArray[i]]];
        }
        model.ids = str;
    }else{
        model.ids = @"";
    }
    
    [[NSNotificationCenter defaultCenter]postNotificationName:firstRequestFocusSuccess object:nil];

  
}

@end
